#ifndef OS_DBG_H
#define OS_DBG_H

#include "os_def.h"
#include "os_plat.h"
#include "os_lib.h"

/**
 * 调试信息打印
*/
#if OS_DBG_PRINT_ENABLE
#define os_dbg(fmt, ...)   do {\
    os_printf("%s(%d):", __FUNCTION__, __LINE__);  \
    os_printf(fmt, ##__VA_ARGS__); } while (0)
#else
#define os_dbg(fmt, ...)        
#endif // OS_DEBUG_ENABLE

/**
 * os断言，当表达式不成立时，整个系统死机
 */
#if OS_ASSERT_ENABLE
#define os_assert(expr)    do {\
    if (!(expr))       {\
        os_printf("assert failed: %s!\n", #expr);    \
        os_plat_int_disable();	\
        while(1);\
    }   \
}while(0)
#else
#define os_assert(expr)
#endif // OS_ASSERT_ENABLE

/**
 * 参数检查
 */
#if OS_PARAM_CHECK_ENABLE
#define os_param_failed(expr, ret)  do {\
    if (expr)   {\
        os_dbg("%s\n", #expr);    \
        return (ret);   \
    }   \
}while (0)

#define os_param_failed_exec(expr, ret, exec)  do {\
    if (expr)   {\
        {exec;}; \
        os_dbg("%s\n", #expr);    \
        return (ret);   \
    };   \
} while (0)
#else 
#define os_param_failed(expr, ret)
#define os_param_failed_exec(expr, ret, exec)
#endif

#endif // OS_DBG_H
